package com.control.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import org.hibernate.Session;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.model.entity.Student;
import com.model.imp.AdminImp;
import com.model.imp.StudentImp;

public class LoginServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html; charset=UTF-8");
		this.doPost(request, response);
	}


	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		//1 得到输入数据
		 String stuname=request.getParameter("stuname");
		 String password=request.getParameter("password");
		//2 调用数据库验证
		 //request.setAttribute("stuname", stuname); 
		 request.getSession().setAttribute("stuname", stuname);
		 if(new AdminImp().login(stuname, password)!=null){
		        
		//3 根据结果，跳转 ListServlet.java
			 request.setAttribute("currentPageNo", "1");
	    	request.getRequestDispatcher("index.jsp").forward(request, response);
	    	System.out.println("denglucheng");
		  }else {
			     response.sendRedirect("login.jsp");
			  
		  }
		  
	}

}
